// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_FIN_SUPPLIER_ACCOUNT_ITEM
// * CreateDate    : 2012/2/2 10:17:12
// * Creater       : CodeSmith
// * LastChangeDate: 2012/2/2 10:17:12
// * LastChanger   : 2012/2/2 10:17:12
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Fin
{
/// <summary>
    /// FinSupplierAccountItem
    /// </summary>
    public partial class FinSupplierAccountItemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objFinSupplierAccountItemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static FinSupplierAccountItemEntity GetFinSupplierAccountItem(FinSupplierAccountItemEntity objFinSupplierAccountItemEntity)
        {
            return DataAccess.SelectSingle<FinSupplierAccountItemEntity>(objFinSupplierAccountItemEntity);
        }
        public static FinSupplierAccountItemEntity GetByID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            FinSupplierAccountItemEntity entity = new FinSupplierAccountItemEntity();
            entity.SupplierAccountItemId = id;
            return DataAccess.SelectSingle<FinSupplierAccountItemEntity>(entity);
        }
        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"SAI.*, S.SUPPLIER_NAME, P.NAME_CN
                                FROM FIN_SUPPLIER_ACCOUNT_ITEM SAI
                                LEFT JOIN MST_SUPPLIER S ON S.SUPPLIER_ID = SAI.SUPPLIER_ID
                                LEFT JOIN MST_PERSON P ON P.PERSON_ID = SAI.AMOUNT_PERSON
                                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        public static DataTable GetTotalByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"SA.SUPPLIER_ID, S.SUPPLIER_NAME, SUM(SA.PURCHASE_ORDER_AMOUNT) AS PURCHASE_ORDER_AMOUNT, 
								SUM(SA.BILLING_AMOUNT) AS BILLING_AMOUNT, 
								SUM(SA.PAID_AMOUNT) AS PAID_AMOUNT, 
								SUM(SA.PAYABLE_AMOUNT) AS PAYABLE_AMOUNT, 
								SUM(SA.ARRIVED_AMOUNT_NO_BILLING) AS ARRIVED_AMOUNT_NO_BILLING, 
								SUM(ISNULL(SA.ARRIVED_AMOUNT_NO_BILLING,0) - ISNULL(SA.BILLING_AMOUNT,0)) AS ARRIVED_AMOUNT_NON_BILLED
                                FROM FIN_SUPPLIER_ACCOUNT_ITEM SA
                                LEFT JOIN MST_SUPPLIER S ON S.SUPPLIER_ID = SA.SUPPLIER_ID
                                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            sql += " GROUP BY SA.SUPPLIER_ID, S.SUPPLIER_NAME ";
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objFinSupplierAccountItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertFinSupplierAccountItem(FinSupplierAccountItemEntity objFinSupplierAccountItemEntity)
        {
            return DataAccess.Insert(objFinSupplierAccountItemEntity);
        }

        public static bool InsertFinSupplierAccountItem(List<FinSupplierAccountItemEntity> objFinSupplierAccountItemEntityList)
        {
            return DataAccess.Insert(objFinSupplierAccountItemEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objFinSupplierAccountItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateFinSupplierAccountItem(FinSupplierAccountItemEntity objFinSupplierAccountItemEntity)
        {
            return DataAccess.Update(objFinSupplierAccountItemEntity);
        }

        public static bool UpdateFinSupplierAccountItem(List<FinSupplierAccountItemEntity> objFinSupplierAccountItemEntityList)
        {
            return DataAccess.Update<FinSupplierAccountItemEntity>(objFinSupplierAccountItemEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objFinSupplierAccountItemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteFinSupplierAccountItem(FinSupplierAccountItemEntity objFinSupplierAccountItemEntity)
        {
            return DataAccess.Delete(objFinSupplierAccountItemEntity);
        }

        public static bool DeleteFinSupplierAccountItem(List<FinSupplierAccountItemEntity> objFinSupplierAccountItemEntityList)
        {
            return DataAccess.Delete<FinSupplierAccountItemEntity>(objFinSupplierAccountItemEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetFinSupplierAccountItemAll()
        {
            return DataAccess.SelectAllDataSet<FinSupplierAccountItemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<FinSupplierAccountItemEntity> GetFinSupplierAccountItemAllList()
        {
            return DataAccess.SelectAll<FinSupplierAccountItemEntity>();
        }
        #endregion
	}
	
	
}	

